<?php

class Administration_Model_Mapper_News extends Jnd_Model_Mapper_Abstract
{
	
    protected $_dict = array(
        'id' => 'idnews', 
        'title' => 'title', 
        'message' => 'message', 
    	'creationUser' => 'creationuser',
    	'creationDate' => 'creationdate'
    );
    
    protected $_dictDate = array(
    	'creationDate' => 'creationdate'
    );
    
    
	/**
     * Methode permettant de générer le Table_Select pour le datagrid
     * @see Jnd_Model_Mapper_Abstract::getListSelect()
     */
    public function getListSelect( $values, $environnement, $identite, $options = null )
    {
        $table = $this->_getTable();
        $tableName = $table->info(Zend_Db_Table_Abstract::NAME);
        $dba = $table->getAdapter();
        $select = $dba->select()->from($tableName, $this->_dict, $table->info(Zend_Db_Table_Abstract::SCHEMA));

        $champ = 'title';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'message';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'creationUtilisateur';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'creationDate';
        if (isset($values[$champ]) && $values[$champ]) {
            $dt = new Jnd_Date($values[$champ], null, 'fr_FR');
            $select->where('DATE(' . $dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ') = ?', $dt->getDbDate());
        }
        //      echo $select;
//        die("Select : $select");
        return $select;
    }
}
